<template>
  <div>
    <div class="card">
      <div class="photo">
        <img src="@/assets/img/kk.gif" alt />
      </div>
      <h1>{{userName}}</h1>
      <h2>打篮球；rapper；</h2>
    </div>
  </div>
</template>
<script setup>
const userName = localStorage.getItem("username");
</script>
<style scoped>
.card {
  /* 相对定位 */
  position: relative;
  width: 300px;
  height: 450px;
  margin: 20px;
  background-color: #1ed411;
  border-radius: 20px;
  /* 溢出隐藏 */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  /* 阴影 */
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  color: #fff;
  left: calc(50% - 150px);
  top: calc(40vh - 300px);
}

/* 默认大图 */
.card .photo {
  /* 绝对定位 */
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 0%;
  overflow: hidden;
  /* 动画过渡 */
  transition: 0.5s;
}

/* 鼠标移入变小图 */
.card:hover .photo {
  top: 30px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}

/* 黑色到透明的渐变背景,可以更好的看清楚名字 */
.card .photo::before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, transparent 50%, #222);
}

/* 鼠标移入背景消失 */
.card:hover .photo::before {
  display: none;
}

.card .photo img {
  width: 100%;
  height: 100%;
  /* 保持原有尺寸比例，裁切长边 */
  object-fit: cover;
}

.card h1 {
  position: absolute;
  top: 370px;
  transition: 0.5s;
  font-size: 28px;
  color: aqua;
}

.card:hover h1 {
  top: 170px;
  font-size: 28px;
  color: rgb(255, 136, 0);
}

.card h2 {
  margin-top: 220px;
  width: 80%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 20px;
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 20px;
}

.card p {
  width: 90%;
  text-indent: 32px;
  font-size: 16px;
  margin-bottom: 15px;
  line-height: 30px;
}
</style>